<!-- 网络管理 -->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="关键字" prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="请输入网络名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属渠道" prop="channelId">
        <SelectChannel :defaultValue.sync="queryParams.channelId" />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb-8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >创建网络</el-button
        >
      </el-col>
      <el-col v-if="userInfo.userType === 2" :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-circle-plus-outline"
          size="mini"
          @click="handleJoin"
          >加入网络</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="groupsList">
      <el-table-column
        label="网络码"
        prop="networkCode"
        align="center"
        width="120"
      ></el-table-column>
      <el-table-column
        label="网络图标"
        prop="networkIcon"
        align="center"
        width="120"
      >
        <template slot-scope="{ row }">
          <image-preview
            v-if="row.networkIcon"
            :src="row.networkIcon"
            :width="30"
            :height="30"
          />
        </template>
      </el-table-column>
      <el-table-column label="网络名称" prop="networkName" align="center">
        <template slot-scope="{ row }">
          <div class="colorZS cup" @click="goDetails(row)">{{ row.networkName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="网络成员数"
        prop="networkMember"
        align="center"
        width="100"
      />
      <el-table-column
        label="网络创建人"
        prop="creatorName"
        align="center"
        width="100"
      />
      <el-table-column label="网络负责单位" prop="manageCompany" align="center" />
      <el-table-column label="网络所属渠道" prop="channelName" align="center" />
      <el-table-column
        label="创建时间"
        prop="createTime"
        align="center"
        width="200"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <EditMesh ref="EditMesh" @refresh="getList" />
    <JoinMesh ref="JoinMesh" @refresh="getList" />
  </div>
</template>

<script>

import { getNetworkList } from "@/api/mesh/index.js";
import EditMesh from "./editMesh"
import JoinMesh from './joinMesh'
import SelectChannel from '@/components/SelectChannel';

export default {
  name: "Mesh",
  components: {
    EditMesh,
    JoinMesh,
    SelectChannel
  },
  computed: {
    userInfo() {
      return this.$store.state.user.userInfo;
    }
  },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: "",
        channelId: ""
      },
      groupsList: [],
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      getNetworkList(this.queryParams).then((response) => {
        this.groupsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleAdd() {
      this.$refs.EditMesh.openDialog()
    },
    handleJoin() {
      this.$refs.JoinMesh.openDialog()
    },
    goDetails(row){
      this.$router.push({path: `/mesh/meshDetails/index/${row.networkId}`});
    }
  },
};
</script>

<style lang="scss" scoped></style>
